package com.example.leetdemo.finash;

public class Solution2006 {
    public int countKDifference(int[] nums, int k) {
        int[] t = new int[101];
        int result = 0;
        for (int i = 0; i < nums.length; i++) {
            t[nums[i]]++;
        }
        for (int i = 0; i < t.length - k; i++) {
            if (t[i] != 0 && t[i + k - 1] != 0) {
                result += t[i] * t[i + k];
            }
        }
        return result;
    }

    public static void main(String[] args) {
        Solution2006 solution2006 = new Solution2006();
        System.err.println(solution2006.countKDifference(new int[] {1,2,2,1}, 1));
    }
}
